package com.task.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.util.ObjectUtils;

/**
 * @Author 迪迦.
 * @Date 2023/5/18 17:41
 */
public enum OrderByTypeEnum {
  DESC(0, "DESC", "降序"),
  ASC(1, "ASC", "升序"),
  ;

  private Integer info;
  private String displayName;
  private String msg;


  OrderByTypeEnum(Integer info, String displayName, String msg) {
    this.info = info;
    this.displayName = displayName;
    this.msg = msg;
  }

  public static OrderByTypeEnum getEnumByInfo(int info) {
    if (!ObjectUtils.isEmpty(info)) {
      for (OrderByTypeEnum value : OrderByTypeEnum.values()) {
        if (info == value.getInfo()) {
          return value;
        }
      }
    }
    return OrderByTypeEnum.DESC;
  }

  /**
   * 获取列表.
   */
  public static List<Map<String, Object>> getList() {
    List<Map<String, Object>> list = new ArrayList<>();
    for (OrderByTypeEnum value : OrderByTypeEnum.values()) {
      Map<String, Object> map = new HashMap<>();
      map.put("value", value.getInfo());
      map.put("label", value.getMsg());
      map.put("displayName", value.getDisplayName());
      list.add(map);
    }
    return list;
  }

  OrderByTypeEnum() {
  }

  public Integer getInfo() {
    return info;
  }

  public String getDisplayName() {
    return displayName;
  }

  public String getMsg() {
    return msg;
  }
}
